<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <div id="app">
        <input type="button" value="修改" @click="changeUrl">
        <img v-bind:src="url" ><br/>
        <img v-mybind:src="url" >
        <input type="text" v-mybind:value="username" >

    </div>

    
    <script src="./js/vue.js"></script>
    <script>

        Vue.directive("mybind",{
            // bind:是在指令和dom元素初次绑定时，调用
            bind:function(el,binding){
                el[binding.arg] = binding.value
            },
            // （指令所在的）dom元素插入到父节点（可以认为此时，dom元素已经渲染）时，调用
            inserted:function(el){
                
            },
            // 当指令所绑定的数据发生变化时，调用
            update:function(el,binding){
                el[binding.arg] = binding.value
            }
        });

        let vm = new Vue({
            el:"#app",
            data:{
                url:"./imgs/1.jpg",
                username:"王一星"
            },
            methods:{
                changeUrl(){
                   this.url="./imgs/2.jpg";
                }
            }
        });


    </script>
</body>
</html>